<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>光功率与衰减监测系统</title>
    <script src="https://cdn.jsdelivr.net/npm/echarts@5.4.3/dist/echarts.min.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #0c1e2c, #152b3c);
            color: #e0f0ff;
            min-height: 100vh;
            padding: 20px;
            overflow-x: hidden;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            position: relative;
        }

        .header-gradient {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 350px;
            background: linear-gradient(90deg, rgba(0, 100, 200, 0.15), rgba(0, 150, 255, 0.1));
            z-index: -1;
            border-radius: 0 0 50% 50%;
            transform: scale(1.5, 1);
        }

        header {
            text-align: center;
            padding: 30px 0 20px;
            margin-bottom: 10px;
            position: relative;
            z-index: 1;
        }

        h1 {
            font-size: 2.5rem;
            margin-bottom: 8px;
            color: #ffffff;
            letter-spacing: 1px;
            text-shadow: 0 2px 10px rgba(0, 150, 255, 0.4);
            background: linear-gradient(to right, #a0d8ff, #ffffff);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 700;
        }

        .subtitle {
            font-size: 1.2rem;
            color: #a0d8ff;
            max-width: 800px;
            margin: 0 auto;
            line-height: 1.6;
        }

        .system-info {
            display: flex;
            justify-content: space-between;
            background: rgba(16, 42, 67, 0.6);
            border-radius: 12px;
            padding: 18px 30px;
            margin: 25px 0;
            box-shadow: 0 8px 24px rgba(0, 40, 80, 0.4);
            border: 1px solid rgba(64, 180, 255, 0.25);
            backdrop-filter: blur(5px);
        }

        .info-item {
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .info-label {
            font-size: 1rem;
            color: #a0d8ff;
            margin-bottom: 8px;
            font-weight: 500;
        }

        .info-value {
            font-size: 1.6rem;
            font-weight: 700;
            color: #4dccff;
            text-shadow: 0 0 10px rgba(77, 204, 255, 0.5);
        }

        .info-unit {
            font-size: 1rem;
            color: #88c0e0;
            margin-left: 4px;
        }

        .formula-card {
            background: rgba(16, 42, 67, 0.85);
            border-radius: 15px;
            padding: 25px;
            margin: 20px 0 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
            border: 1px solid rgba(64, 224, 208, 0.15);
            position: relative;
            overflow: hidden;
        }

        .formula-card::before {
            content: "";
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(64, 224, 208, 0.1) 0%, transparent 70%);
            z-index: 0;
        }

        .formula-title {
            color: #4dccff;
            margin-bottom: 15px;
            font-size: 1.5rem;
            font-weight: 700;
            position: relative;
            z-index: 1;
        }

        .formula-box {
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 20px;
        }

        .formula-content {
            flex: 1;
            min-width: 300px;
            background: rgba(0, 20, 40, 0.6);
            border-radius: 12px;
            padding: 20px;
            border-left: 4px solid #40e0d0;
            position: relative;
            z-index: 1;
        }

        .formula {
            font-family: 'Courier New', monospace;
            font-size: 1.6rem;
            color: #ffcc66;
            margin: 20px 0;
            padding: 15px;
            background: rgba(0, 0, 0, 0.3);
            border-radius: 8px;
            text-align: center;
            border: 1px solid rgba(255, 204, 102, 0.3);
            box-shadow: 0 0 15px rgba(255, 204, 102, 0.1);
        }

        .formula-explanation {
            color: #c0e8f0;
            line-height: 1.7;
            font-size: 1.1rem;
        }

        .formula-diagram {
            flex: 1;
            min-width: 300px;
            background: rgba(0, 20, 40, 0.6);
            border-radius: 12px;
            padding: 20px;
            position: relative;
            z-index: 1;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        .diagram-title {
            color: #4dccff;
            margin-bottom: 15px;
            font-size: 1.2rem;
            font-weight: 600;
        }

        .diagram {
            width: 100%;
            height: 180px;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
        }

        .fiber-line {
            width: 80%;
            height: 4px;
            background: linear-gradient(to right, #ffcc66, #ff9966);
            border-radius: 2px;
            position: relative;
            box-shadow: 0 0 10px rgba(255, 204, 102, 0.4);
        }

        .fiber-line::before {
            content: "";
            position: absolute;
            top: -3px;
            left: 0;
            right: 0;
            height: 10px;
            background: repeating-linear-gradient(90deg, 
                transparent, 
                transparent 5px, 
                rgba(255, 255, 255, 0.1) 5px, 
                rgba(255, 255, 255, 0.1) 10px);
            border-radius: 5px;
        }

        .input-point, .output-point {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            width: 24px;
            height: 24px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 0.9rem;
        }

        .input-point {
            left: -12px;
            background: linear-gradient(135deg, #4dccff, #0066cc);
            box-shadow: 0 0 15px rgba(77, 204, 255, 0.6);
            color: white;
        }

        .output-point {
            right: -12px;
            background: linear-gradient(135deg, #ff9966, #ff6600);
            box-shadow: 0 0 15px rgba(255, 153, 102, 0.6);
            color: white;
        }

        .power-label {
            position: absolute;
            top: -30px;
            font-size: 0.9rem;
            color: #a0d8ff;
            white-space: nowrap;
        }

        .attenuation-label {
            position: absolute;
            bottom: -30px;
            font-size: 0.9rem;
            color: #ff9966;
            text-align: center;
            width: 100%;
        }

        .content {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 25px;
            margin-bottom: 30px;
        }

        @media (max-width: 992px) {
            .content {
                grid-template-columns: 1fr;
            }
        }

        .chart-container {
            background: rgba(16, 42, 67, 0.7);
            border-radius: 15px;
            padding: 20px 20px 15px;
            box-shadow: 0 8px 24px rgba(0, 40, 80, 0.4);
            border: 1px solid rgba(64, 180, 255, 0.25);
            position: relative;
            overflow: hidden;
            backdrop-filter: blur(5px);
        }

        .chart-container::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, #4dccff, #40e0d0);
        }

        .chart-title {
            color: #4dccff;
            margin-bottom: 15px;
            font-size: 1.4rem;
            display: flex;
            align-items: center;
            gap: 10px;
            font-weight: 600;
        }

        .chart-title i {
            font-size: 1.6rem;
        }

        .chart {
            height: 400px;
            width: 100%;
        }

        .event-marker {
            position: absolute;
            top: 20px;
            right: 20px;
            background: rgba(255, 77, 77, 0.2);
            padding: 8px 20px;
            border-radius: 20px;
            border: 1px solid rgba(255, 77, 77, 0.5);
            font-size: 0.95rem;
            color: #ff9999;
            font-weight: 500;
            z-index: 10;
        }

        .export-btn {
            position: absolute;
            top: 20px;
            right: 20px;
            z-index: 10;
            background: linear-gradient(90deg, #4dccff, #40e0d0);
            border: none;
            border-radius: 8px;
            color: #0c1e2c;
            font-size: 1rem;
            font-weight: 600;
            padding: 8px 20px;
            cursor: pointer;
            box-shadow: 0 4px 12px rgba(77, 204, 255, 0.3);
            transition: all 0.3s ease;
        }

        .export-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 6px 16px rgba(77, 204, 255, 0.5);
        }

        .status-bar {
            display: flex;
            justify-content: space-between;
            margin-top: 15px;
            padding-top: 15px;
            border-top: 1px solid rgba(64, 180, 255, 0.2);
        }

        .status-item {
            display: flex;
            flex-direction: column;
            align-items: center;
            flex: 1;
        }

        .status-value {
            font-size: 1.3rem;
            font-weight: 700;
            margin-bottom: 5px;
        }

        .status-normal {
            color: #81c784;
        }

        .status-warning {
            color: #ffb300;
        }

        .status-critical {
            color: #f44336;
        }

        .status-label {
            font-size: 0.95rem;
            color: #a0d8ff;
        }

        footer {
            text-align: center;
            padding: 30px 0;
            margin-top: 40px;
            color: #88c0e0;
            font-size: 1rem;
            border-top: 1px solid rgba(64, 224, 208, 0.2);
        }

        .legend {
            display: flex;
            justify-content: center;
            flex-wrap: wrap;
            gap: 20px;
            margin-top: 15px;
        }

        .legend-item {
            display: flex;
            align-items: center;
            font-size: 0.95rem;
        }

        .legend-color {
            width: 22px;
            height: 22px;
            margin-right: 8px;
            border-radius: 4px;
        }

        .legend-estimated {
            background: #4dccff;
        }

        .legend-actual {
            background: #ff9966;
        }

        .fiber-animation {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            pointer-events: none;
            z-index: -1;
        }

        .fiber-light {
            position: absolute;
            width: 200px;
            height: 2px;
            background: linear-gradient(90deg, transparent, #4dccff, transparent);
            box-shadow: 0 0 15px rgba(77, 204, 255, 0.8);
            opacity: 0.3;
        }

        @keyframes moveLight {
            0% { transform: translateX(-100%); }
            100% { transform: translateX(100vw); }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header-gradient"></div>
        
        <div class="fiber-animation">
            <div class="fiber-light" style="top: 15%; animation: moveLight 8s linear infinite;"></div>
            <div class="fiber-light" style="top: 35%; animation: moveLight 12s linear infinite; animation-delay: -4s;"></div>
            <div class="fiber-light" style="top: 65%; animation: moveLight 10s linear infinite; animation-delay: -2s;"></div>
            <div class="fiber-light" style="top: 85%; animation: moveLight 15s linear infinite; animation-delay: -7s;"></div>
        </div>

        <header>
            <h1>光功率与衰减监测系统</h1>
            <div class="subtitle">实时监测光纤链路性能，基于物理公式精准计算衰减值：衰减(dB) = P<sub>in</sub>(dBm) - P<sub>out</sub>(dBm)</div>
        </header>

        <div class="system-info">
            <div class="info-item">
                <div class="info-label">输入光功率 (P<sub>in</sub>)</div>
                <div class="info-value">-5.00 <span class="info-unit">dBm</span></div>
            </div>
            <div class="info-item">
                <div class="info-label">光纤长度</div>
                <div class="info-value">50.0 <span class="info-unit">km</span></div>
            </div>
            <div class="info-item">
                <div class="info-label">测量波长</div>
                <div class="info-value">1550 <span class="info-unit">nm</span></div>
            </div>
            <div class="info-item">
                <div class="info-label">衰减系数</div>
                <div class="info-value">0.25 <span class="info-unit">dB/km</span></div>
            </div>
        </div>

        <div class="formula-card">
            <div class="formula-title">光功率衰减计算公式</div>
            <div class="formula-box">
                <div class="formula-content">
                    <div class="formula">衰减(dB) = P<sub>in</sub>(dBm) - P<sub>out</sub>(dBm)</div>
                    <div class="formula-explanation">
                        <p>在光纤通信系统中，衰减是衡量信号在传输过程中功率损失的重要指标。该公式表示：</p>
                        <p><strong>衰减值(dB)</strong> = <strong>输入光功率(dBm)</strong> - <strong>输出光功率(dBm)</strong></p>
                        <p>其中：</p>
                        <ul>
                            <li>P<sub>in</sub>：发射端注入光纤的光功率（单位：dBm）</li>
                            <li>P<sub>out</sub>：接收端检测到的光功率（单位：dBm）</li>
                            <li>衰减值：表示光信号在光纤中传输的总损耗（单位：dB）</li>
                        </ul>
                        <p>衰减值越大，表示信号损失越严重。在长距离传输中，通常还需要计算单位长度的衰减（dB/km）。</p>
                    </div>
                </div>
                <div class="formula-diagram">
                    <div class="diagram-title">光纤传输衰减示意图</div>
                    <div class="diagram">
                        <div class="fiber-line">
                            <div class="input-point">P<sub>in</sub></div>
                            <div class="output-point">P<sub>out</sub></div>
                            <div class="power-label" style="left: 0;">-5.00 dBm</div>
                            <div class="power-label" style="right: 0;">-17.50 dBm</div>
                            <div class="attenuation-label">衰减 = P<sub>in</sub> - P<sub>out</sub> = 12.50 dB</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="content">
            <div class="chart-container">
                <button class="export-btn" onclick="exportChart('powerChart')">导出图表</button>
                <div class="chart-title">
                    <i>📶</i> 光功率变化趋势
                </div>
                <div id="powerChart" class="chart"></div>
                <div class="status-bar">
                    <div class="status-item">
                        <div class="status-value status-normal">-17.8 dBm</div>
                        <div class="status-label">当前输出光功率</div>
                    </div>
                    <div class="status-item">
                        <div class="status-value status-warning">12.2 dB</div>
                        <div class="status-label">当前总衰减</div>
                    </div>
                    <div class="status-item">
                        <div class="status-value status-normal">0.244 dB/km</div>
                        <div class="status-label">当前衰减系数</div>
                    </div>
                </div>
            </div>

            <div class="chart-container">
                <button class="export-btn" onclick="exportChart('attenuationChart')">导出图表</button>
                <div class="chart-title">
                    <i>📉</i> 衰减变化趋势
                </div>
                <div id="attenuationChart" class="chart"></div>
                <div class="status-bar">
                    <div class="status-item">
                        <div class="status-value status-normal">0.244 dB/km</div>
                        <div class="status-label">当前衰减系数</div>
                    </div>
                    <div class="status-item">
                        <div class="status-value status-warning">12.2 dB</div>
                        <div class="status-label">当前总衰减</div>
                    </div>
                    <div class="status-item">
                        <div class="status-value status-critical">1</div>
                        <div class="status-label">异常事件</div>
                    </div>
                </div>
            </div>
        </div>

        <div class="legend">
            <div class="legend-item">
                <div class="legend-color legend-estimated"></div>
                <div>预估曲线</div>
            </div>
            <div class="legend-item">
                <div class="legend-color legend-actual"></div>
                <div>实际测量</div>
            </div>
        </div>

        <footer>
            <p>光功率与衰减监测系统 &copy; 2025 | 基于物理公式：衰减(dB) = P<sub>in</sub>(dBm) - P<sub>out</sub>(dBm)</p>
        </footer>
    </div>

    <script>
        // 使用正确的光功率衰减公式
        // 衰减值 (dB) = P_in (dBm) - P_out (dBm)
        
        // 系统参数
        const P_in = -5.00; // 输入光功率 dBm
        const L = 50;       // 光纤长度 km
        const alpha = 0.25; // 衰减系数 dB/km
        
        // 生成30组光功率数据
        let outputPowers = [];
        // 正常功率基线
        const normalP_out = P_in - alpha * L; // 公式: P_out = P_in - α*L
        
        // 前19组：正常波动
        for (let i = 0; i < 19; i++) {
            let delta = (Math.random() * 0.2 + 0.05) * (Math.random() > 0.5 ? 1 : -1);
            outputPowers.push(Number((normalP_out + delta).toFixed(2)));
        }
        
        // 中间5组：异常衰减（衰减系数增加到0.4 dB/km）
        const abnormalP_out = P_in - 0.4 * L;
        for (let i = 0; i < 5; i++) {
            let delta = (Math.random() * 0.3 + 0.1) * (Math.random() > 0.5 ? 1 : -1);
            outputPowers.push(Number((abnormalP_out + delta).toFixed(2)));
        }
        
        // 后6组：恢复正常
        for (let i = 0; i < 6; i++) {
            let delta = (Math.random() * 0.2 + 0.05) * (Math.random() > 0.5 ? 1 : -1);
            outputPowers.push(Number((normalP_out + delta).toFixed(2)));
        }
        
        // 计算衰减值数组
        let attenuationArr = outputPowers.map(P_out => (P_in - P_out).toFixed(2));
        // 计算衰减系数数组（单位 dB/km）
        let alphaArr = outputPowers.map(P_out => ((P_in - P_out) / L).toFixed(3));
        
        // x轴时间数据
        const startDate = new Date('2025-06-04T17:00:00');
        const timeData = Array.from({ length: outputPowers.length }, (_, i) => {
            let d = new Date(startDate.getTime() - (outputPowers.length - 1 - i) * 60 * 60 * 1000);
            return `${d.getHours().toString().padStart(2, '0')}:00`;
        });
        
        // 光功率图表配置
        const powerOption = {
            backgroundColor: 'transparent',
            tooltip: {
                trigger: 'axis',
                backgroundColor: 'rgba(16, 42, 67, 0.95)',
                borderColor: 'rgba(64, 180, 255, 0.5)',
                borderWidth: 1,
                textStyle: { color: '#e0f0ff', fontWeight: 'bold' },
                axisPointer: { 
                    type: 'cross', 
                    label: { 
                        backgroundColor: '#4dccff',
                        color: '#0c1e2c',
                        fontWeight: 'bold'
                    } 
                },
                formatter: function (params) {
                    const time = params[0].name;
                    const estimated = params[0].value;
                    const actual = params[1].value;
                    const attenuation = (P_in - actual).toFixed(2);
                    const alphaVal = (attenuation / L).toFixed(3);
                    
                    let status = '<span style="color:#81c784">正常</span>';
                    if (actual < estimated - 1.0) status = '<span style="color:#ffb300">警告</span>';
                    if (actual < estimated - 2.0) status = '<span style="color:#f44336">严重</span>';
                    
                    return `
                        <div><strong>时间:</strong> ${time}</div>
                        <div><strong>预估:</strong> ${estimated} dBm</div>
                        <div><strong>测量:</strong> ${actual} dBm</div>
                        <div><strong>总衰减:</strong> ${attenuation} dB</div>
                        <div><strong>衰减系数:</strong> ${alphaVal} dB/km</div>
                        <div><strong>状态:</strong> ${status}
                    `;
                }
            },
            legend: {
                data: ['预估输出', '实际输出'],
                textStyle: { color: '#e0f0ff', fontWeight: 'bold' },
                backgroundColor: 'rgba(16, 42, 67, 0.7)',
                borderRadius: 8,
                padding: [8, 20],
                top: 10,
                right: 20,
                borderColor: 'rgba(64, 180, 255, 0.3)',
                borderWidth: 1
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '12%',
                top: 70,
                containLabel: true
            },
            xAxis: {
                type: 'category',
                data: timeData,
                axisLabel: {
                    color: '#88c0e0',
                    fontWeight: '500',
                    fontSize: 12,
                    interval: 4
                },
                axisLine: { 
                    lineStyle: { 
                        color: 'rgba(64, 180, 255, 0.5)', 
                        width: 2 
                    } 
                },
                axisTick: { show: false }
            },
            yAxis: {
                type: 'value',
                name: '光功率 (dBm)',
                nameTextStyle: { 
                    color: '#88c0e0', 
                    fontWeight: 'bold', 
                    fontSize: 14,
                    padding: [0, 0, 0, -40]
                },
                axisLabel: { 
                    color: '#88c0e0', 
                    fontWeight: '500', 
                    fontSize: 12 
                },
                axisLine: { 
                    lineStyle: { 
                        color: 'rgba(64, 180, 255, 0.5)', 
                        width: 2 
                    } 
                },
                splitLine: { 
                    lineStyle: { 
                        color: 'rgba(64, 180, 255, 0.15)', 
                        type: 'dashed' 
                    } 
                },
                min: Math.min(...outputPowers) - 2,
                max: Math.max(...outputPowers) + 2
            },
            series: [
                {
                    name: '预估输出',
                    type: 'line',
                    data: Array(outputPowers.length).fill(normalP_out.toFixed(2)),
                    smooth: true,
                    symbol: 'none',
                    lineStyle: { 
                        width: 3, 
                        color: '#4dccff',
                        type: 'dashed'
                    },
                    areaStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                            { offset: 0, color: 'rgba(77, 204, 255, 0.1)' },
                            { offset: 1, color: 'rgba(77, 204, 255, 0.01)' }
                        ])
                    }
                },
                {
                    name: '实际输出',
                    type: 'line',
                    data: outputPowers,
                    smooth: true,
                    symbol: 'circle',
                    symbolSize: 8,
                    itemStyle: {
                        color: '#ff9966',
                        borderColor: '#0c1e2c',
                        borderWidth: 2
                    },
                    lineStyle: { 
                        width: 4, 
                        color: '#ff9966' 
                    },
                    emphasis: {
                        focus: 'series',
                        itemStyle: { 
                            borderColor: '#ffffff', 
                            borderWidth: 3,
                            shadowBlur: 10,
                            shadowColor: '#ff9966'
                        }
                    },
                    markPoint: {
                        data: [
                            { 
                                type: 'max', 
                                name: '最大值',
                                symbol: 'pin',
                                symbolSize: 50,
                                itemStyle: { color: '#81c784' }
                            },
                            { 
                                type: 'min', 
                                name: '最小值',
                                symbol: 'pin',
                                symbolSize: 50,
                                itemStyle: { color: '#f44336' }
                            }
                        ]
                    }
                }
            ]
        };
        
        // 衰减图表配置
        const attenuationOption = {
            backgroundColor: 'transparent',
            tooltip: {
                trigger: 'axis',
                backgroundColor: 'rgba(16, 42, 67, 0.95)',
                borderColor: 'rgba(64, 180, 255, 0.5)',
                borderWidth: 1,
                textStyle: { color: '#e0f0ff', fontWeight: 'bold' },
                axisPointer: { 
                    type: 'cross', 
                    label: { 
                        backgroundColor: '#ff9966',
                        color: '#0c1e2c',
                        fontWeight: 'bold'
                    } 
                },
                formatter: function (params) {
                    const time = params[0].name;
                    const estimated = params[0].value;
                    const actual = params[1].value;
                    const attenuation = (actual * L).toFixed(2);
                    
                    let status = '<span style="color:#81c784">正常</span>';
                    if (actual > estimated + 0.05) status = '<span style="color:#ffb300">警告</span>';
                    if (actual > estimated + 0.1) status = '<span style="color:#f44336">严重</span>';
                    
                    return `
                        <div><strong>时间:</strong> ${time}</div>
                        <div><strong>预估系数:</strong> ${estimated} dB/km</div>
                        <div><strong>测量系数:</strong> ${actual} dB/km</div>
                        <div><strong>总衰减:</strong> ${attenuation} dB</div>
                        <div><strong>状态:</strong> ${status}
                    `;
                }
            },
            legend: {
                data: ['预估衰减系数', '实际衰减系数'],
                textStyle: { color: '#e0f0ff', fontWeight: 'bold' },
                backgroundColor: 'rgba(16, 42, 67, 0.7)',
                borderRadius: 8,
                padding: [8, 20],
                top: 10,
                right: 20,
                borderColor: 'rgba(64, 180, 255, 0.3)',
                borderWidth: 1
            },
            grid: {
                left: '3%',
                right: '4%',
                bottom: '12%',
                top: 70,
                containLabel: true
            },
            xAxis: {
                type: 'category',
                data: timeData,
                axisLabel: {
                    color: '#88c0e0',
                    fontWeight: '500',
                    fontSize: 12,
                    interval: 4
                },
                axisLine: { 
                    lineStyle: { 
                        color: 'rgba(64, 180, 255, 0.5)', 
                        width: 2 
                    } 
                },
                axisTick: { show: false }
            },
            yAxis: {
                type: 'value',
                name: '衰减系数 (dB/km)',
                nameTextStyle: { 
                    color: '#88c0e0', 
                    fontWeight: 'bold', 
                    fontSize: 14,
                    padding: [0, 0, 0, -40]
                },
                axisLabel: { 
                    color: '#88c0e0', 
                    fontWeight: '500', 
                    fontSize: 12 
                },
                axisLine: { 
                    lineStyle: { 
                        color: 'rgba(64, 180, 255, 0.5)', 
                        width: 2 
                    } 
                },
                splitLine: { 
                    lineStyle: { 
                        color: 'rgba(64, 180, 255, 0.15)', 
                        type: 'dashed' 
                    } 
                },
                min: Math.min(...alphaArr) - 0.05,
                max: Math.max(...alphaArr) + 0.05
            },
            series: [
                {
                    name: '预估衰减系数',
                    type: 'line',
                    data: Array(alphaArr.length).fill(alpha.toFixed(3)),
                    smooth: true,
                    symbol: 'none',
                    lineStyle: { 
                        width: 3, 
                        color: '#4dccff',
                        type: 'dashed'
                    },
                    areaStyle: {
                        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                            { offset: 0, color: 'rgba(77, 204, 255, 0.1)' },
                            { offset: 1, color: 'rgba(77, 204, 255, 0.01)' }
                        ])
                    }
                },
                {
                    name: '实际衰减系数',
                    type: 'line',
                    data: alphaArr,
                    smooth: true,
                    symbol: 'circle',
                    symbolSize: 8,
                    itemStyle: {
                        color: '#81c784',
                        borderColor: '#0c1e2c',
                        borderWidth: 2
                    },
                    lineStyle: { 
                        width: 4, 
                        color: '#81c784' 
                    },
                    emphasis: {
                        focus: 'series',
                        itemStyle: { 
                            borderColor: '#ffffff', 
                            borderWidth: 3,
                            shadowBlur: 10,
                            shadowColor: '#81c784'
                        }
                    },
                    markPoint: {
                        data: [
                            { 
                                type: 'max', 
                                name: '最大值',
                                symbol: 'pin',
                                symbolSize: 50,
                                itemStyle: { color: '#f44336' }
                            },
                            { 
                                type: 'min', 
                                name: '最小值',
                                symbol: 'pin',
                                symbolSize: 50,
                                itemStyle: { color: '#4dccff' }
                            }
                        ]
                    },
                    markArea: {
                        itemStyle: {
                            color: 'rgba(255, 77, 77, 0.1)'
                        },
                        data: [[
                            {
                                name: '异常事件',
                                xAxis: timeData[19],
                                itemStyle: {
                                    color: 'rgba(255, 77, 77, 0.1)',
                                    borderColor: 'rgba(255, 77, 77, 0.3)',
                                    borderWidth: 1
                                }
                            },
                            {
                                xAxis: timeData[23]
                            }
                        ]]
                    }
                }
            ]
        };
        
        // 初始化图表
        const powerChart = echarts.init(document.getElementById('powerChart'));
        const attenuationChart = echarts.init(document.getElementById('attenuationChart'));
        powerChart.setOption(powerOption);
        attenuationChart.setOption(attenuationOption);
        
        // 响应窗口大小变化
        window.addEventListener('resize', function() {
            powerChart.resize();
            attenuationChart.resize();
        });
        
        // 导出图表函数
        function exportChart(chartId) {
            const chart = echarts.getInstanceByDom(document.getElementById(chartId));
            const url = chart.getDataURL({
                type: 'png',
                pixelRatio: 2,
                backgroundColor: '#0c1e2c'
            });
            const a = document.createElement('a');
            a.href = url;
            a.download = chartId === 'powerChart' ? '光功率监测图表.png' : '衰减系数监测图表.png';
            a.click();
        }
    </script>
</body>
</html>